home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / i-fortra.adb < prev    next >
Text File  |  1996-01-30  |  4KB  |  137 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                   I N T E R F A C E S . F O R T R A N                    --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.5 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. package body Interfaces.Fortran is
  27.  
  28.    ------------
  29.    -- To_Ada --
  30.    ------------
  31.  
  32.    --  Single character case
  33.  
  34.    function To_Ada (Item : in Character_Set) return Character is
  35.    begin
  36.       return Character (Item);
  37.    end To_Ada;
  38.  
  39.    --  String case (function returning converted result)
  40.  
  41.    function To_Ada (Item : in Fortran_Character) return String is
  42.       T : String (1 .. Item'Length);
  43.  
  44.    begin
  45.       for J in T'Range loop
  46.          T (J) := Character (Item (J - 1 + Item'First));
  47.       end loop;
  48.  
  49.       return T;
  50.    end To_Ada;
  51.  
  52.    --  String case (procedure copying converted string to given buffer)
  53.  
  54.    procedure To_Ada
  55.      (Item   : in Fortran_Character;
  56.       Target : out String;
  57.       Last   : out Natural)
  58.    is
  59.    begin
  60.       if Item'Length = 0 then
  61.          Last := 0;
  62.          return;
  63.  
  64.       elsif Target'Length = 0 then
  65.          raise Constraint_Error;
  66.  
  67.       else
  68.          Last := Target'First - 1;
  69.  
  70.          for J in Item'Range loop
  71.             Last := Last + 1;
  72.  
  73.             if Last > Target'Last then
  74.                raise Constraint_Error;
  75.             else
  76.                Target (Last) := Character (Item (J));
  77.             end if;
  78.          end loop;
  79.       end if;
  80.    end To_Ada;
  81.  
  82.    ----------------
  83.    -- To_Fortran --
  84.    ----------------
  85.  
  86.    --  Character case
  87.  
  88.    function To_Fortran (Item : in Character) return Character_Set is
  89.    begin
  90.       return Character_Set (Item);
  91.    end To_Fortran;
  92.  
  93.    --  String case (function returning converted result)
  94.  
  95.    function To_Fortran (Item : in String) return Fortran_Character is
  96.       T : Fortran_Character (1 .. Item'Length);
  97.  
  98.    begin
  99.       for J in T'Range loop
  100.          T (J) := Character_Set (Item (J - 1 + Item'First));
  101.       end loop;
  102.  
  103.       return T;
  104.    end To_Fortran;
  105.  
  106.    --  String case (procedure copying converted string to given buffer)
  107.  
  108.    procedure To_Fortran
  109.      (Item   : in String;
  110.       Target : out Fortran_Character;
  111.       Last   : out Natural)
  112.    is
  113.    begin
  114.       if Item'Length = 0 then
  115.          Last := 0;
  116.          return;
  117.  
  118.       elsif Target'Length = 0 then
  119.          raise Constraint_Error;
  120.  
  121.       else
  122.          Last := Target'First - 1;
  123.  
  124.          for J in Item'Range loop
  125.             Last := Last + 1;
  126.  
  127.             if Last > Target'Last then
  128.                raise Constraint_Error;
  129.             else
  130.                Target (Last) := Character_Set (Item (J));
  131.             end if;
  132.          end loop;
  133.       end if;
  134.    end To_Fortran;
  135.  
  136. end Interfaces.Fortran;
  137.